#include<iostream>
#include<bits/stdc++.h>
using namespace std;

typedef struct HNode *Heap;
typedef int ElementType;
struct HNode
{
	ElementType *Data;
	int Size;
	int Capacity;	
};

typedef Heap MaxHeap;
typedef Heap MinHeap;

#define MAXDATA 1000 //最大容量
#define MINDATA -0x3f3f3f3f//最小值
MinHeap CreateHeap(int MinSize)
{
	MinHeap H=(MinHeap)malloc(sizeof(struct HNode));
    H->Data=(ElementType*)malloc((MinSize+1)*sizeof(ElementType));
    H->Size=0;
    H->Capacity=MAXDATA;
    H->Data[0]=MINDATA;//'哨兵'
	
	return H; 
}; 

bool IsFull(MinHeap H)
{
	return (H->Size == H->Capacity);	
};

bool Insert(MinHeap H,ElementType X)
{
	/*插入一个元素自下而上过滤*/
	int i;
	if (IsFull(H)){
		cout<<"最小堆已满\n";
		return false;
	} 
	H->Size++;
	i = H->Size;
	for(;H->Data[i/2]>X;i=i/2){
		H->Data[i] = H->Data[i/2];/*向上过滤 X*/ 
	}
	H->Data[i] = X;/*找到位置插入*/
	return true; 
}
bool IsEmpty(MinHeap H)
{
	return (H->Size==0);
}
ElementType DeleteMin(MinHeap H)
{
	/*从最小堆中删除最小的元素*/
	int Parent ,Child;
	ElementType MinItem,X;
	if(IsEmpty(H)){
		cout<<"最小堆已空\n";
		return -1;
	}
	MinItem = H->Data[1];//?堆顶最小值
	X=H->Data[H->Size];
	H->Size--;
	/*从上往下过滤*/
	for(Parent=1; Parent*2<=H->Size;Parent=Child){
		Child=Parent*2;
		if((Child!=H->Size)&&(H->Data[Child]>H->Data[Child+1]))
			Child++;//右儿子小
		if(X<=H->Data[Child]) break;//找到了合适的位置
		else H->Data[Parent] = H->Data[Child];
	} 
	H->Data[Parent] = X;
	
	return MinItem;
};

int main()
{
	MinHeap T = CreateHeap(5);
	for(int i=1;i<=5;i++){
		int temp;
		cin>>temp;
		Insert(T,temp);
	}
	for(int i=1;i<=5;i++){
		
		cout<<DeleteMin(T)<<endl;
	}
	return 0;
}


